# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

import json
import coin.exchange.base.kr_rest.native_public_client_base as npubcb


class KrakenFuturesNativePublicClient(npubcb.NativePublicClientBase):
  def __init__(self, timeout=1):
    npubcb.NativePublicClientBase.__init__(self,
                                           url='https://futures.kraken.com/derivatives/api/v3',
                                           timeout=timeout)

  @staticmethod
  def _assert_success(content):
    assert content is not None
    assert content['result'] == 'success', content

  def get_instrument(self):
    url = 'instruments'
    update = self._get_as_json(url)
    self._assert_success(update.msg)
    return update

  def get_exchange_tickers(self):
    url = 'tickers'
    update = self._get_as_json(url)
    self._assert_success(update.msg)
    return update

  def queryAll(self):
    print(self.get_instrument())


if __name__ == "__main__":
  client = KrakenFuturesNativePublicClient(timeout=10)
  print(json.dumps(client.get_instrument().msg, indent=2))
  client.queryAll()
